import io.github.lnyocly.ai4j.config.DeepSeekConfig;
import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatCompletion;
import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatCompletionResponse;
import io.github.lnyocly.ai4j.platform.openai.chat.entity.ChatMessage;
import io.github.lnyocly.ai4j.service.Configuration;
import io.github.lnyocly.ai4j.service.IChatService;
import io.github.lnyocly.ai4j.service.PlatformType;
import io.github.lnyocly.ai4j.service.factor.AiService;
import okhttp3.OkHttpClient;

public class DeepseekChat {

    private final OkHttpClient okHttpClient;
    private final String system;

    public DeepseekChat(OkHttpClient okHttpClient, String system) {
        this.okHttpClient = okHttpClient;
        this.system = system;
    }

    public ChatCompletionResponse chat(String content) throws Exception {
        Configuration configuration = new Configuration();
        configuration.setOkHttpClient(okHttpClient);

        DeepSeekConfig dsConfig = new DeepSeekConfig();
        configuration.setDeepSeekConfig(dsConfig);
        dsConfig.setApiHost("https://oneai.17usoft.com/");
        dsConfig.setChatCompletionUrl("v1/chat/completions");
        dsConfig.setApiKey("sk-hCqcTAvgLmtv20q9Ec6HMBn1noC6nhSwwgGqDg5aBIVp27Jt");

        AiService aiService = new AiService(configuration);
        IChatService ds = aiService.getChatService(PlatformType.DEEPSEEK);
        IChatService openai = aiService.getChatService(PlatformType.OPENAI);

        // 构建请求参数
        ChatCompletion chatCompletion = ChatCompletion.builder()
                .model("deepseek-v3")
                .message(ChatMessage.withSystem(system))
                .message(ChatMessage.withUser(content))
                .build();

        // 发送对话请求
        return ds.chatCompletion(chatCompletion);
    }

}
